from PyQt5.QtWidgets import QApplication,QMainWindow,QLabel,QPushButton,qApp,QAction
from PyQt5.QtGui import QIcon
import sys

class Window(QMainWindow):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建一个菜单栏
        menuBar = self.menuBar()
        # 创建一个菜单
        fileMenu = menuBar.addMenu('File')

        # 添加菜单项
        exitAction = QAction(QIcon('python\day10\exit3.png'),'退出',self)
        # 定义快捷键
        exitAction.setShortcut('Ctrl+Q')
        # 给菜单项绑定功能
        exitAction.triggered.connect(qApp.quit)
        # 添加到菜单中
        fileMenu.addAction(exitAction)

        # 创建一个工具栏
        toolBar = self.addToolBar('tool')
        # 给工具栏上添加工具
        toolBar.addAction(exitAction)

        self.setGeometry(1000,300,300,200)
        self.setWindowTitle('菜单与工具栏')
        self.show()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = Window()
    app.exec()